% B3_process_wrf.m 9/27/2011 Parker MacCready
%
% this runs all the wrf extraction post-processing code

clear

% *** USER DEFINED VALUES **********************
dth = 120; % time step for forcing fields (hours) [120, 12, 3, 1]
period_list = {'wrf1a';'wrf1b'};
% *** END USER DEFINED VALUES ******************

switch dth
    case 120
        indir0 = 'split_five_day/';
    case 12
        indir0 = 'split_half_day/';
    case 3
        indir0 = 'split_three_hour/';
    case 1
        indir0 = 'split_hourly/';
    otherwise
        disp('that dth is not coded for')
        break
end

% create the output directory
outdir0 = strrep(indir0,'split','processed');
if ~(exist(outdir0,'dir')==7); mkdir(outdir0); end

stars = '*******************';
disp(' '); disp(' ');

disp(stars)
ZP_rh(indir0,outdir0,period_list);

disp(stars)
ZP_rain(indir0,outdir0,period_list);

disp(stars)
ZP_vel_rotate(indir0,outdir0,period_list);

% and move the things that aren't already moved
g_list = {'d2';'d3'};
disp(stars)
disp('moving things')
for pp = 1:length(period_list)
    period = period_list{pp};
    disp(['period = ',period])
    for gg = 1:length(g_list)
        g_tag = g_list{gg};
        
        indir = [indir0,period,'/'];
        outdir = [outdir0,period,'/'];
        
        copyfile([indir,'psfc_',g_tag,'.mat'], ...
            [outdir,'psfc_',g_tag,'.mat']);
        
        copyfile([indir,'swdown_',g_tag,'.mat'], ...
            [outdir,'swdown_',g_tag,'.mat']);
        
        copyfile([indir,'glw_',g_tag,'.mat'], ...
            [outdir,'lwdown_',g_tag,'.mat']);
        
        copyfile([indir,'t2_',g_tag,'.mat'], ...
            [outdir,'t2_',g_tag,'.mat']);
        
    end % end of gg loop
end

% finally move the results to the mm5 directory so that the regridding is
% done for moth mm5 and wrf files together
for pp = 1:length(period_list)
    period = period_list{pp};
    outdir_old = [outdir0,period,'/'];
    outdir_new = ['../mm5/',outdir0,period,'/'];
    eval(['!mv ',outdir_old,' ',outdir_new]);
end
